<template>
	<div>
		<!-- 投票信息 -->
		<el-table :data="infomation" stripe style="width: 100%">
			<el-table-column prop="name" label="姓名" width="180">
			</el-table-column>
			<el-table-column prop="account" label="学号">
			</el-table-column>
			<el-table-column prop="sex" label="性别">
			</el-table-column>
			<el-table-column prop="info" label="自我介绍">
				<template slot-scope="scope">
					<span v-html="scope.row.info.replace(/\n/g, '<br>')"></span>
				</template>
			</el-table-column>
			<el-table-column prop="counts" label="投票数">
			</el-table-column>
			<el-table-column>
        <template slot-scope="scope">
          <el-popconfirm
              title="确定要投票给他？"
              @confirm="handleConfirm(scope.row.account)"
              @cancel="handleCancel"
          >
            <el-button slot="reference" type="success" round :disabled="dis">投票</el-button>
          </el-popconfirm>
        </template>
			</el-table-column>
		</el-table>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				dis:false,
				infomation: [],
			}
		},
		mounted() {
			this.$http.get("/api/yearPeople").then((resp) => {
				if (resp.data.code == 200)
					this.infomation = resp.data.obj;
			})
			this.$http.get("/api/yearPeopleDo").then((resp) => {
				if (resp.data.code == 200)
					this.dis = true;
			})
		},
		methods: {
      handleConfirm(account) {
        // 处理确认操作
        this.save(account);
        this.$router.push("/info/yearPeople");
        this.$message({
          type: 'success',
          message: '投票成功!'
        });
      },
      handleCancel() {
        // 处理取消操作
        this.$message({
          type: 'success',
          message: '取消投票成功!'
        });
      },
			save(account) {
				// 投票后 关闭投票按钮
				this.$http.post("/api/yearPeopleDo","account="+account).then((resp)=>{
					if(resp.data.code == 200){
						this.$router.go();//更新当前路由路件
					}
				})
			}
		}

	}

	function jsonToString(form) {
		var str = "";
		for (var s in form) {
			str += s + "=" + form[s] + "&";
		}
		return str.substring(0, str.length - 1);
	}
</script>

<style>
	#items {

		width: 70%;
		height: 20%;
	}
</style>